package homeword;
import java.util.Scanner;
//定义3部手机对象
//属性有，品牌，价格，颜色
//计算三部手机的平均价格
public class objectArray3Main {
    public static void main(String[] args) {
        objectArray3 []arr=new objectArray3[3];
        String brand;
        double price;
        String color;
        Scanner scanner=new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            objectArray3 r=new objectArray3();
            System.out.println("请输入手机品牌：");
            brand=scanner.next();
            r.setBrand(brand);
            System.out.println("请输入手机价格：");
            price=scanner.nextDouble();
            r.setPrice(price);
            System.out.println("请输入手机颜色：");
            color=scanner.next();
            r.setColor(color);
            arr[i]=r;
        }
        //遍历数组查看数据
        for (int i = 0; i < arr.length; i++) {
            objectArray3 r=arr[i];
            System.out.println("品牌："+r.getBrand());
            System.out.println("价格："+r.getPrice());
            System.out.println("颜色："+r.getColor());
            System.out.println();
        }
        //计算价格总和
        double sum=0.0;
        for (int i = 0; i < arr.length; i++) {
            objectArray3 r=arr[i];
            sum+=r.getPrice();
        }
        //输出平均值
        System.out.println("三部手机的平均价格为："+sum/arr.length);
    }
}
